Bring Qstrings to gt_find_desc_from_icon_number,
authortsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 19 Oct 2014 19:04:27 +0000 (19:04 +0000)
committertsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 19 Oct 2014 19:04:27 +0000 (19:04 +0000)
and a few other places.

13 files changed:
gpsbabel/bcr.cc
gpsbabel/compegps.cc
gpsbabel/g7towin.cc
gpsbabel/garmin.cc
gpsbabel/garmin_tables.cc
gpsbabel/garmin_tables.h
gpsbabel/garmin_txt.cc
gpsbabel/gdb.cc
gpsbabel/lowranceusr.cc
gpsbabel/mapsource.cc
gpsbabel/pcx.cc
gpsbabel/psitrex.cc
gpsbabel/tpg.cc

index d1e2347176c54a2fe7c4388c84dd8bca94cdf828..d71d48a24e474f216f3a556a9edf0e38ccb9c265 100644 (file)
@@ -146,7 +146,7 @@ bcr_handle_icon_str(const char* str, Waypoint* wpt)
       wpt->description = m->symbol_DE;
       if (m->mps_name != NULL) {
         nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE);
-        wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE, NULL);
+        wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE);
       }
       return;
     }
index d5ea38d1fa0b9c7cde963d072f0ec17a6abdf553..b6a57f3c1db9092af19fb1ce09c25d91dfe7275b 100644 (file)
@@ -500,7 +500,7 @@ write_waypt_cb(const Waypoint* wpt)
   }
   gbfprintf(fout, "\n");
 
-  if ((wpt->icon_descr != NULL) || (wpt->wpt_flags.proximity) || \
+  if ((!wpt->icon_descr.isNull()) || (wpt->wpt_flags.proximity) || \
       (option_icon != NULL)) {
     gbfprintf(fout, "w  %s,0,0.0,16777215,255,1,7,,%.1f\n",
               wpt->icon_descr.isNull() ? "Waypoint" : CSTR(wpt->icon_descr),
index 7df56a125a805b8f9d104c342352525de76dd040..cfbd5271daa4e706bde0f2a26e29ea15ee24abda 100644 (file)
@@ -89,7 +89,7 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt)
 
     switch (index) {
 
-      int categories, dyn;
+      int categories;
       struct tm tm;
       char* cerr;
 
@@ -114,7 +114,7 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt)
 
     case WAYPT__OFS + 2:
       wpt->icon_descr = gt_find_desc_from_icon_number(
-                          atoi(cin), PCX, &dyn);
+                          atoi(cin), PCX);
       break;
 
     case WAYPT__OFS + 4:
@@ -466,11 +466,9 @@ data_read(void)
         cdata++;
       }
       if (*cdata == ';') {
-        int dyn;
-
         cdata++;
         wpt->icon_descr = gt_find_desc_from_icon_number(
-                            atoi(cdata), PCX, &dyn);
+                            atoi(cdata), PCX);
       }
       waypt_add(wpt);
       break;
index bb629a452d48f8d0a1ddbbc630769cb2f781e318..bce74331901ef9cf87a5b2ed57f096703d8fa643 100644 (file)
@@ -399,9 +399,8 @@ waypt_read(void)
       wpt_tmp->icon_descr = d103_symbol_from_icon_number(
                               way[i]->smbl);
     } else {
-      int dyn = 0;
       wpt_tmp->icon_descr = gt_find_desc_from_icon_number(
-                              way[i]->smbl, PCX, &dyn);
+                              way[i]->smbl, PCX);
     }
     /*
      * If a unit doesn't store altitude info (i.e. a D103)
index 40412879d87f5689c7cee9cd042ed357b68e8dcb..f08d201edbeb304c6ac4605da70c223edf6af963 100644 (file)
@@ -731,29 +731,18 @@ gt_switch_display_mode_value(const unsigned char display_mode, const int protoid
   }
 }
 
-const char*
-gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, int* dynamic)
+const QString 
+gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format)
 {
-  icon_mapping_t* i;
-  char custom[] = "Custom 63 ";
-
   if ((garmin_format == GDB) && (icon >= 500) && (icon <= 563)) {
-    snprintf(custom, sizeof(custom), "Custom %d", icon - 500);
-    *dynamic = 1;
-    return xstrdup(custom);
+    return QString("Custom %d").arg(icon - 500);
   }
 
   if ((garmin_format == PCX) && (icon >= 7680) && (icon <= 8191)) {
-    snprintf(custom, sizeof(custom), "Custom %d", icon - 7680);
-    *dynamic = 1;
-    return xstrdup(custom);
+    return QString("Custom %d").arg(icon - 7680);
   }
 
-  if (dynamic) {
-    *dynamic = 0;
-  }
-
-  for (i = garmin_icon_table; i->icon; i++) {
+  for (icon_mapping_t* i = garmin_icon_table; i->icon; i++) {
     switch (garmin_format) {
     case MAPSOURCE:
     case GDB:
index 2e2252909eae2f95b1b06bc71f2ca0594fb7bee0..8f2b13b9f445ed0a4135f732d634baf2dcf49c69 100644 (file)
@@ -36,7 +36,7 @@ typedef struct icon_mapping {
 
 typedef enum {MAPSOURCE, PCX, GARMIN_SERIAL, GDB} garmin_formats_e;
 
-const char* gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, int* dynamic);
+const QString gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format);
 int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_format);
 
 extern icon_mapping_t garmin_icon_table[];
index c88ed950e2383e8d512af0f4f4aa1ff691796b83..4b5e33904f9d136390e3d622ce30a39c1c5162f2 100644 (file)
@@ -544,8 +544,7 @@ write_waypt(const Waypoint* wpt)
   const char* dspl_mode;
   const char* country;
   double x;
-  int i, icon, dynamic;
-  const char* icon_descr;
+  int i, icon;
 
   gmsd = GMSD_FIND(wpt);
 
@@ -609,12 +608,7 @@ write_waypt(const Waypoint* wpt)
   if (icon == -1) {
     icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB);
   }
-  icon_descr = gt_find_desc_from_icon_number(icon, GDB, &dynamic);
-  print_string("%s\t", icon_descr);
-  if (dynamic) {
-    // sleaze alert: cast away constness.
-    xfree((char*) icon_descr);
-  }
+  print_string("%s\t", gt_find_desc_from_icon_number(icon, GDB));
 
   print_string("%s\t", GMSD_GET(facility, ""));
   print_string("%s\t", GMSD_GET(city, ""));
@@ -1126,7 +1120,7 @@ parse_waypoint(void)
   fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
 
   while ((str = csv_lineparse(NULL, "\t", "", column++))) {
-    int i, dynamic;
+    int i;
     double d;
     int field_no = header_fields[waypt_header][column];
 
@@ -1179,7 +1173,7 @@ parse_waypoint(void)
     case 11:
       i = gt_find_icon_number_from_desc(str, GDB);
       GMSD_SET(icon, i);
-      wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic);
+      wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB);
       break;
     case 12:
       GMSD_SETSTR(facility, str);
index 929de7112ab1d86be40bb7737e8d2e6ed67e7c97..0698570912a9a9e1694270374a4342dde4bcd24a 100644 (file)
@@ -525,7 +525,7 @@ static Waypoint*
 read_waypoint(gt_waypt_classes_e* waypt_class_out)
 {
   char buf[128];               /* used for temporary stuff */
-  int display, icon, dynamic;
+  int display, icon;
   gt_waypt_classes_e wpt_class;
   int i;
   Waypoint* res;
@@ -744,7 +744,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out)
     GMSD_SETSTR(postal_code, bufp);
   }
 
-  res->icon_descr = gt_find_desc_from_icon_number(icon, GDB, &dynamic);
+  res->icon_descr = gt_find_desc_from_icon_number(icon, GDB);
 
 #if GDB_DEBUG
   DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON)
index 42cd8640b432758b1548f53126bedf5dd8a43e87..d786d8ab28d886805a2df285ff3e467431c62916 100644 (file)
@@ -253,7 +253,7 @@ lowranceusr_readstr(char* buf, const int maxlen, gbfile* file)
   return len;
 }
 
-const char*
+const QString
 lowranceusr_find_desc_from_icon_number(const int icon)
 {
   const lowranceusr_icon_mapping_t* i;
index 166d51c320905354c343f09807eada0d23269e20..0fb9f7955e28a0ed170207ae28cf4a4c2f1cda9a 100644 (file)
@@ -520,7 +520,6 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, Waypoint** wpt, unsigned int* mpsc
   int lat;
   int lon;
   int  icon;
-  int dynamic;
 
   Waypoint*    thisWaypoint = NULL;
   double       mps_altitude = unknown_alt;
@@ -597,7 +596,7 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, Waypoint** wpt, unsigned int* mpsc
   }
 
   /* might need to change this to handle version dependent icon handling */
-  thisWaypoint->icon_descr = gt_find_desc_from_icon_number(icon, MAPSOURCE, &dynamic);
+  thisWaypoint->icon_descr = gt_find_desc_from_icon_number(icon, MAPSOURCE);
 
   /* The following Now done elsewhere since it can be useful to read in and
     perhaps not add to the list */
index 6132b714d5f3718c2146c5780ff8321146224691..7aff32e4240271a1073fca72a7e61744a397fb15 100644 (file)
@@ -163,7 +163,7 @@ data_read(void)
       if (*cp != '\0') {
         wpt_tmp->description = cp;
       }
-      wpt_tmp->icon_descr = gt_find_desc_from_icon_number(symnum, PCX, NULL);
+      wpt_tmp->icon_descr = gt_find_desc_from_icon_number(symnum, PCX);
 
       if (read_as_degrees || read_gpsu) {
         human_to_dec(tbuf, &lat, &lon, 1);
index ec4f83c2c92a1d638c6143a6ce80cfdd1bc4eda3..328733730e0f92a98607b990db61b77b2783c107 100644 (file)
@@ -326,7 +326,7 @@ psit_waypoint_r(gbfile* psit_file, Waypoint** wpt)
     /* since PsiTrex only deals with Garmins, let's use the "proper" Garmin icon name */
     /* convert the PsiTrex name to the number, which is the PCX one; from there to Garmin desc */
     garmin_icon_num = psit_find_icon_number_from_desc(psit_current_token);
-    thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX, NULL);
+    thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX);
 
     waypt_add(thisWaypoint);
 
@@ -448,7 +448,7 @@ psit_route_r(gbfile* psit_file, route_head** rte)
       /* since PsiTrex only deals with Garmins, let's use the "proper" Garmin icon name */
       /* convert the PsiTrex name to the number, which is the PCX one; from there to Garmin desc */
       garmin_icon_num = psit_find_icon_number_from_desc(psit_current_token);
-      thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX, NULL);
+      thisWaypoint->icon_descr = gt_find_desc_from_icon_number(garmin_icon_num, PCX);
 
       route_add_wpt(rte_head, thisWaypoint);
 
@@ -472,7 +472,7 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte)
 {
   char         hdr[20];
   unsigned int rte_datapoints;
-  char*                rname;
+  QString      rname;
 
   Waypoint*    testwpt;
   time_t               uniqueValue = 0;
@@ -501,18 +501,14 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte)
 
     /* route name */
     if (rte->rte_name.isEmpty()) {
-      sprintf(hdr, "Route%04x", (unsigned) uniqueValue);
-      rname = xstrdup(hdr);
+      rname = QString("Route%1").arg((uint) uniqueValue, 4, 16, QChar('0'));
     } else {
-      rname = xstrdup(rte->rte_name);
+      rname = rte->rte_name;
     }
     /* check for psitrex comment sign; replace with '$' */
-    while ((c = strchr(rname, '#'))) {
-      *c = '$';
-    }
+    rname = rname.replace(QChar('#'), QChar('$'));
 
-    gbfprintf(psit_file, "Route:  %s\n", rname);
-    xfree(rname);
+    gbfputs(QString("Route:  %1\n").arg(rname), psit_file);
   }
 }
 
@@ -633,7 +629,7 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk)
 {
   char         hdr[30];
   unsigned int trk_datapoints;
-  char*                tname;
+  QString      tname;
   Waypoint*    testwpt;
   time_t               uniqueValue = 0;
 
@@ -659,20 +655,15 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk)
 
       /* track name */
       if (trk->rte_name.isEmpty()) {
-        sprintf(hdr, "Track%04x", (unsigned) uniqueValue);
-        tname = xstrdup(hdr);
+        tname = QString("Track%1").arg((uint) uniqueValue, 4, 16, QChar('0'));
       } else {
-        tname = xstrdup(trk->rte_name);
+        tname = trk->rte_name;
       }
 
       /* check for psitrex comment sign; replace with '$' */
-      while ((c = strchr(tname, '#'))) {
-        *c = '$';
-      }
-
-      gbfprintf(psit_file, "Track:  %s\n", tname);
+      tname = tname.replace(QChar('#'), QChar('$'));
 
-      xfree(tname);
+      gbfputs(QString("Track:  %1\n").arg(tname), psit_file);
     }
   }
   psit_track_state = 1;
index 9db086a0487623d9191a2d3680c2294d9b0f6e58..4655245f439d1d12190957a89f0ced2fafd30e47 100644 (file)
@@ -195,11 +195,11 @@ tpg_waypt_pr(const Waypoint* wpt)
       if (global_opts.synthesize_shortnames) {
         shortname = mkshort_from_wpt(mkshort_handle, wpt);
       } else {
-        shortname = xstrdup(wpt->description);
+        shortname = wpt->description;
       }
     } else {
       /* no description available */
-      shortname = xstrdup("");
+      shortname = "";
     }
   } else {
     shortname = wpt->shortname;